package com.lecture.java8.excel.dyr;

import com.alibaba.excel.EasyExcel;
import com.lecture.java8.excel.DemoDataListener;
import com.lecture.java8.excel.dyr.model.Model0325;
import com.lecture.java8.excel.dyr.model.Result0325;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test0325 {
    public static void main(String[] args) {
        String dir = "D:\\study\\tmp\\0325\\1\\";
        String dataResultFileName = dir + "result.xlsx";
        DemoDataListener<Result0325> dataResultListener = new DemoDataListener<>();
        EasyExcel.read(dataResultFileName, Result0325.class,dataResultListener).sheet().doRead();
        List<Result0325> resultList = dataResultListener.getDataList();

        Map<String,String> resultMap = new HashMap<>();
        for (Result0325 result : resultList) {
            resultMap.put(result.getA() + "-" ,result.getC());
        }
        //Map<String, String> resultMap = resultList.stream().collect(Collectors.toMap(r -> r.getId() + "-" + r.getYear(), Result0320::getEast));



        String dataFileName = dir + "正在使用的.xlsx";
        DemoDataListener<Model0325> dataListener = new DemoDataListener<>();
        EasyExcel.read(dataFileName, Model0325.class,dataListener).sheet().doRead();
        List<Model0325> financeList = dataListener.getDataList();
        for (Model0325 finance : financeList) {
            String s = resultMap.get(finance.getA() + "-");
            Double result = Double.parseDouble(s);
            if (result > 639.35186803874D) {
                finance.setAp(s);
                finance.setAq("1");
            } else {
                finance.setAp(s);
                finance.setAq("0");
            }
        }

        EasyExcel.write( dir + "正在使用的-结果.xlsx", Model0325.class)
                .sheet("a").doWrite(financeList);

    }
}
